package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.commen.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;


    @Override
    public PageResult<Role> roleList(String name, String label, Integer page, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(page,pageSize);
        //调用mapper,查询
      List<Role> roleList  = roleMapper.selectList(name,label);
//        3.封装成PageResult
       Page<Role> pageData= (Page<Role>) roleList;
       return new PageResult<>(pageData.getTotal(),pageData.getResult());

    }

    @Override
    public void delete(Integer id) {
        roleMapper.delete(id);
    }

    @Override
    public void add(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.insert(role);

    }

    @Override
    public Role getById(Integer id) {

        return roleMapper.getById(id);
    }

    @Override
    public void update(Role role) {
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.update(role);

    }

    /**
     * 查询所有
     */
    @Override
    public List<Role> listAll() {

        List<Role> list = roleMapper.listAll();
        return list;
    }


}
